﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Configuration;

namespace Project20
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public List<Bank> GetAllTransactions()
        {
            List<Bank> result = new List<Bank>();
            string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();

            string sel = "SELECT Player.[Username], Player.[Balance], Player.[Password] FROM Player ";
            OleDbCommand cmdSelect = new OleDbCommand(sel, conn);
            OleDbDataReader set = cmdSelect.ExecuteReader();
            while (set.Read())
            {
                Bank bank = new Bank();
                bank.Username = set["Username"] != null ? Convert.ToString(set["Username"]) : null;
                bank.Balance = set["Balance"] != null ? Convert.ToInt32(set["Balance"]) : 0;
                bank.Password = set["Password"] != null ? Convert.ToString(set["Password"]) : null;
                result.Add(bank);
            }
            return result;
        }

        [WebMethod]
        public List<Bank> GetPlayerTransactions(string Username)
        {
            List<Bank> result = new List<Bank>();
            string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();

            string sel = "SELECT Player.[Username], Player.[Balance] FROM Player WHERE Player.[Username]=? ORDER BY Player.[Username]";
            OleDbCommand cmdSelect = new OleDbCommand(sel, conn);

            cmdSelect.Parameters.AddWithValue("?", Username);
            OleDbDataReader set = cmdSelect.ExecuteReader();
            while (set.Read())
            {
                Bank bank = new Bank();
                bank.Username = set["Username"] != null ? Convert.ToString(set["Username"]) : null;
                bank.Balance = set["Balance"] != null ? Convert.ToInt32(set["Balance"]) : 0;
                result.Add(bank);
            }
            return result;
        }
    }


}
